import devconsts
import json
import os

from google.appengine.api import users
from google.appengine.ext.webapp import template


def getMain(user, user_student_model, students, is_dev_mode):
  tmpl_data = {
    'css_links': getCssLinks(is_dev_mode),
    'footer_html': getFooer(),
    'header_html': getHeader(user),
    'is_dev_mode': is_dev_mode,
    'students_json': json.dumps(students),
    'user_json': json.dumps(user_student_model.to_dict())
  }
  path = os.path.join(os.path.dirname(__file__), 'main.html')
  return template.render(path, tmpl_data)

def getInvalidUser(user, is_dev_mode):
  tmpl_data = {
    'css_links': getCssLinks(is_dev_mode),
    'footer_html': getFooer(),
    'header_html': getHeader(user),
    'login_url': users.create_login_url('/'),
    'user': user
  }
  path = os.path.join(os.path.dirname(__file__), 'invaliduser.html')
  return template.render(path, tmpl_data)

def getComingSoon(user, is_dev_mode):
  tmpl_data = {
    'css_links': getCssLinks(is_dev_mode),
    'footer_html': getFooer(),
    'header_html': getHeader(user)
  }
  path = os.path.join(os.path.dirname(__file__), 'comingsoon.html')
  return template.render(path, tmpl_data)

def getPrizes(user, is_dev_mode):
  tmpl_data = {
    'css_links': getCssLinks(is_dev_mode),
    'footer_html': getFooer(),
    'header_html': getHeader(user),
    'is_dev_mode': is_dev_mode
  }
  path = os.path.join(os.path.dirname(__file__), 'prizes.html')
  return template.render(path, tmpl_data)

def getHeader(user):
  tmpl_data = {
    'logout_url': users.create_logout_url('/'),
    'user': user
  }
  path = os.path.join(os.path.dirname(__file__), 'header.html')
  return template.render(path, tmpl_data)

def getFooer():
  path = os.path.join(os.path.dirname(__file__), 'footer.html')
  return template.render(path, {})

def getCssLinks(is_dev_mode):
  tmpl_data = {
    'dev_css_files': devconsts.DEV_CSS_FILES,
    'is_dev_mode': is_dev_mode
  } 
  path = os.path.join(os.path.dirname(__file__), 'csslinks.html')
  return template.render(path, tmpl_data)
